package com.xingshang.controller;


import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.xingshang.pojo.Song;
import com.xingshang.pojo.User;
import com.xingshang.service.MusicService;
import com.xingshang.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("music")
public class MusicController {
    @Autowired
    MusicService musicService;

    @GetMapping("hello")
    public String hello(String name) {
        return "hello world";
    }

    @GetMapping("/rankList/hot")
    public Result hot() {
        return musicService.getSongsFromRankList("https://qq-music-api-main.vercel.app/getRanks?topId=26");
//        return musicService.getSongsFromRankList("http://localhost:3200/getRanks?topId=26");
    }

    @PostMapping("/info")
    public Result info(@RequestBody Song song,@RequestHeader String token) throws JsonProcessingException {
        return musicService.getSongInfo(song.getMid(), song.getQ(), token);
    }

    @PostMapping("/search")
    public Result search(@RequestBody Song song) {
        System.out.println(song);
        return musicService.getSongListBySearch(song.getTitle());
    }

    @GetMapping("/hot_search")
    public Result hot_search() {
        return musicService.getHotSearch();
    }


    /**
     * 获取推荐歌单
     * @return
     */
    @GetMapping("/recomPlaylist")
    public Result recomPlaylist() {
        System.out.println("获取推荐歌单");
        return musicService.getRecomPlaylist();

    }

    /**
     * 分类专区
     */
    @GetMapping("/category")
    public Result category(@RequestParam String id) {
        return musicService.getCategory(id);
    }


}
